<template>
  <div :class="{ 'dark-mode': isDarkMode }" class="title-bar">
    <div class="left-section">
      <div class="brand-title">Knowledge Nebula</div>
    </div>

    <div class="right-section">
      <!-- Element Plus Switch -->
      <el-switch
        v-model="isDarkMode"
        :active-icon="Moon"
        :inactive-icon="Sunny"
        inline-prompt
        @change="toggleDarkMode"
      />

      <!-- Element Plus About Button -->
      <el-button :icon="InfoFilled" circle class="info-button" @click="toggleInfo" />
    </div>

    <!-- Info Modal -->
    <el-dialog
      v-model="showInfo"
      :modal-class="isDarkMode ? 'dark-mode' : ''"
      align-center
      title="关于"
      width="500px"
    >
      <p>
        Knowledge
        Nebula（知识星云）是一个致力于通过关系图谱展示全人类知识体系的开源项目。通过结合大语言模型（LLM）的强大能力，我们试图构建一个完整的知识类目图谱，展现知识之间的内在联系，帮助人们更好地理解和掌握知识的全貌。
      </p>
      <p>知识的描述信息、关联关系等信息，都由AI自动生成，可能存在错误，请谨慎使用。</p>
    </el-dialog>
  </div>
</template>

<script lang="ts" setup>
import { useThemeStore } from '@/stores/theme'
import { storeToRefs } from 'pinia'
import { ref } from 'vue'
import { InfoFilled, Moon, Sunny } from '@element-plus/icons-vue'

const themeStore = useThemeStore()
const { isDarkMode } = storeToRefs(themeStore)
const showInfo = ref(false)

const toggleDarkMode = (value: boolean) => {
  isDarkMode.value = value
  localStorage.setItem('darkMode', value.toString())
  updateTheme()
}

const toggleInfo = () => {
  showInfo.value = !showInfo.value
}

const updateTheme = () => {
  document.documentElement.classList.toggle('dark-theme', isDarkMode.value)
}
</script>

<style scoped>
.title-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 12px;
  height: 40px;
  background-color: #ffffff;
  color: #333333;
  width: 100%;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
}

.title-bar.dark-mode {
  background-color: #1a1a1a;
  color: #ffffff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.left-section {
  display: flex;
  align-items: center;
  height: 100%;
}

.right-section {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 100%;
}

.brand-title {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.3px;
}

/* Element Plus 组件样式覆盖 */
:deep(.el-switch) {
  --el-switch-on-color: #4a5568;
  --el-switch-off-color: #e2e8f0;
  height: 22px;
}

:deep(.el-switch.is-checked .el-switch__core) {
  background-color: var(--el-switch-on-color);
}

:deep(.el-button.info-button) {
  padding: 6px;
  height: 28px;
  width: 28px;
}

:deep(.el-dialog) {
  border-radius: 8px;
}

:deep(.el-dialog.dark-mode) {
  background-color: #2a2a2a;
  color: #ffffff;
}

:deep(.el-dialog.dark-mode .el-dialog__header) {
  color: #ffffff;
}

:deep(.el-dialog.dark-mode .el-dialog__body) {
  color: #ffffff;
}

:deep(.el-dialog__body) {
  padding: 20px 24px;
}

:deep(.el-dialog__body p) {
  margin-bottom: 12px;
  line-height: 1.5;
  font-size: 0.875rem;
}

:deep(.el-dialog__header) {
  margin-right: 0;
  padding: 20px 24px 0;
}

:deep(.el-dialog__headerbtn) {
  top: 16px;
  right: 16px;
}

/* 暗色模式下的按钮样式 */
.dark-mode :deep(.el-button) {
  --el-button-bg-color: transparent;
  --el-button-border-color: transparent;
  --el-button-hover-bg-color: rgba(255, 255, 255, 0.1);
  --el-button-hover-border-color: transparent;
  color: #ffffff;
}

.dark-mode :deep(.el-button:hover) {
  color: #ffffff;
}
</style>
